package com.carbohydrate42.kotlin_compose_demo.page

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.carbohydrate42.kotlin_compose_demo.module.EasyBottomSheetDialog

@Composable
fun BlankLayoutPage(
) {
    var visible1 by remember {
        mutableStateOf(false)
    }
    var visible2 by remember {
        mutableStateOf(false)
    }

    var visible3 by remember {
        mutableStateOf(false)
    }

    var visible4 by remember {
        mutableStateOf(false)
    }

    Column {
        Button(onClick = {
            visible1 = true
        }) {
            Text(text = "ShowDialog1")
        }
        Text(text = "visible1 : $visible1")

        Button(onClick = {
            visible2 = true
        }) {
            Text(text = "ShowDialog2")
        }
        Text(text = "visible2 : $visible2")

        Button(onClick = {
            visible3 = true
        }) {
            Text(text = "ShowDialog3")
        }
        Text(text = "visible3 : $visible3")

        Button(onClick = {
            visible4 = true
        }) {
            Text(text = "ShowDialog4")
        }
        Text(text = "visible4 : $visible4")
    }

    BottomDialog(visible = visible1, onVisibleChange = {visible1 = it})
    BottomDialog(visible = visible2, onVisibleChange = {visible2 = it})
    BottomDialog(visible = visible3, onVisibleChange = {visible3 = it})
    BottomDialog(visible = visible4, onVisibleChange = {visible4 = it})
}

@Composable
private fun BottomDialog(visible: Boolean, onVisibleChange: (Boolean) -> Unit) {

    EasyBottomSheetDialog(
        modifier = Modifier,
        visible = visible,
        cancelable = true,
        canceledOnTouchOutside = true,
        onDismissRequest = {
            onVisibleChange(false)
        }
    ) {
        Column(
            modifier = Modifier
                .fillMaxWidth()
                .fillMaxHeight(fraction = 0.7f)
                .clip(shape = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp))
                .background(color = Color(0xFF009688)),
            verticalArrangement = Arrangement.Center
        ) {
            Button(
                modifier = Modifier
                    .align(alignment = Alignment.CenterHorizontally),
                onClick = {
                    onVisibleChange(false)
                }) {
                Text(
                    modifier = Modifier.padding(all = 4.dp),
                    text = "dismissDialog",
                    fontSize = 16.sp
                )
            }
        }
    }
}